package com.siyu.preplan.planpdocument.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.siyu.common.core.controller.BaseController;
import com.siyu.common.core.domain.AjaxResult;
import com.siyu.common.core.page.TableDataInfo;
import com.siyu.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.siyu.preplan.planpdocument.domain.PlanPDocument;
import com.siyu.preplan.planpdocument.service.IPlanPDocumentService;

/**
 * 预案文档信息Controller
 *
 * @author hrhy
 * @date 2024-06-15
 */
@RestController
@RequestMapping("/preplan/planpdocument")
public class PlanPDocumentController extends BaseController
{
    @Autowired
    private IPlanPDocumentService planPDocumentService;

    /**
     * 查询预案文档信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PlanPDocument planPDocument)
    {
        startPage();
        List<PlanPDocument> list = planPDocumentService.selectPlanPDocumentList(planPDocument);
        return getDataTable(list);
    }

    /**
     * 导出预案文档信息列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlanPDocument planPDocument)
    {
        List<PlanPDocument> list = planPDocumentService.selectPlanPDocumentList(planPDocument);
        ExcelUtil<PlanPDocument> util = new ExcelUtil<PlanPDocument>(PlanPDocument.class);
        util.exportExcel(response, list, "预案文档信息数据");
    }

    /**
     * 获取预案文档信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(planPDocumentService.selectPlanPDocumentById(id));
    }

    /**
     * 新增预案文档信息
     */
    @PostMapping
    public AjaxResult add(@RequestBody PlanPDocument planPDocument)
    {
        return toAjax(planPDocumentService.insertPlanPDocument(planPDocument));
    }

    /**
     * 修改预案文档信息
     */
    @PutMapping
    public AjaxResult edit(@RequestBody PlanPDocument planPDocument)
    {
        return toAjax(planPDocumentService.updatePlanPDocument(planPDocument));
    }

    /**
     * 删除预案文档信息
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(planPDocumentService.deletePlanPDocumentByIds(ids));
    }
}
